package jm.mq.consumers;

import com.rabbitmq.client.CancelCallback;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DeliverCallback;
import jm.mq.utils.RabbitMQUtils;

/**
 * @Description 优先级队列消费者
 * @date 2022/3/14 15:16
 */
public class Consumer {
    // 指定队列名称
    private static final String QUEUE_NAME = "priority_queue";

    public static void main(String[] args) throws Exception {

        // 获取信道
        Channel channel = RabbitMQUtils.getChannel();

        // 声明：接收消息回调
        DeliverCallback deliverCallback = (consumerTag, message) -> {
            System.out.println("工作线程接收："+ new String(message.getBody()));
        };

        // 声明：取消消费回调
        CancelCallback cancelCallback = consumerTag -> {
            System.out.println("工作线程取消："+consumerTag);
        };


        channel.basicConsume(QUEUE_NAME,false,deliverCallback,cancelCallback);
    }
}
